CurrentVersion = 0.1
GM.Name 	= "FreezeTag Reborn"
GM.Author 	= "Lex148"
GM.Email 	= "lexchilds@gmail.com"
GM.Website 	= "N/A"

DeriveGamemode("base")

TEAM_IT = 1
TEAM_NOTIT = 2
TEAM_NOTIT_F = 3
SKIN_IT = "models/player/zombie_soldier.mdl"
SKIN_NOTIT_F = "models/player/police.mdl"
SKIN_NOTIT = "models/player/barney.mdl"
TIME_FREEZE_BOMB = 5
TIME_FREEZE_BOMB_MAX = 50
TIME_ROUND = 180
TIME_ROUND_MAX = 180
WIN = 0

function GM:SetupTeams()

	team.SetUp(TEAM_IT, "IT", Color(255, 0, 0, 255))  
	team.SetUp(TEAM_NOTIT, "Not It", Color(255, 255, 255, 255))  
	team.SetUp(TEAM_NOTIT_F, "Not It: Frozen", Color(100, 100, 255, 255) )  
end

function GM:EqualizeTeams()		
	self.PickANewIt()	
	return 
end



function UpdatePlayerSkin(ply, frooze)
	if ply:Team() == TEAM_NOTIT or ply:Team() == TEAM_NOTIT_F then
		if frooze then
			ply:SetModel( SKIN_NOTIT_F ) 
			ply:SetColor( 50,50,255,255)
			ply:SetTeam( TEAM_NOTIT_F )
		else
			ply:SetModel( SKIN_NOTIT ) 
			ply:SetColor( 255,255,255,255)
			ply:SetTeam( TEAM_NOTIT )
		end
	end
end




function GM:EndRound(winningteam)
		
	GAMEMODE:EqualizeTeams()	
	
end

function GM:RestartRound()
	for k,v in pairs(player.GetAll()) do
		v:StripWeapons()
		v:Thaw()
		v:Spawn()
		v:Notice("The round has begun!")
		v:GodDisable()
		v:ClientSound(GameInfo.StartRound)
	end
end


function GM:EndGame(winningteam)	
end


function ChooseRandom(tablename)
		return tablename[math.random(1,table.Count(tablename))]
end



function KeyPressed (P, key)
   if key == IN_ATTACK2 then
	if P:Team() == TEAM_IT and TIME_FREEZE_BOMB < 1 then
		FreezeBomb( P )
		TIME_FREEZE_BOMB = TIME_FREEZE_BOMB_MAX
	end
   end
   
   if key == IN_USE and DrawWin then
		DrawWin( TEAM_IT )
   end
   
end
hook.Add( "KeyPress", "KeyPressedHook", KeyPressed ) 



function FreezeBomb(plyIt)
	local vPoint = plyIt:GetPos()
	local effectdata = EffectData()
	local radius = 150
	effectdata:SetStart( vPoint ) // not sure if we need a start and origin (endpoint) for this effect, but whatever
	effectdata:SetOrigin( vPoint )
	effectdata:SetScale( 1 )
	effectdata:SetRadius( 10000 )
	util.Effect( "HelicopterMegaBomb", effectdata ) 
	
	//puch the player away from the blast
	for k,v in pairs(player.GetAll()) do
		util.BlastDamage(plyIt, plyIt, vPoint, radius, 1)  
		if v:Team() != TEAM_IT then
			local vBlast = v:GetPos() - vPoint
			vBlast = vBlast + Vector( 0, 0, 50 ) 
			if vBlast:Length() < radius then
				local vNorm = vBlast:GetNormal()
				vNorm = vNorm * 1000
				if vNorm != nil and v != nil then
					if v.SetLocalVelocity then
					v:SetLocalVelocity( vNorm )
					end
				end
			end
		end
	end
	
end







